<?php 
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";    

//----
//Ingresa aqui cuando da submit en la forma para modificar o eliminar definitivo
//----
if ($_REQUEST["hidId1"] != "") {
    switch ($_REQUEST["opc"]) {
        case "M":
            $strSql ="update solotb_nivel3 set ";
            $strSql .= "des='"  . ($_REQUEST["newds3"]) . "' ";
            //$strSql .= "where id2=" . $_REQUEST["hidId2"];
            $strSql .= "  where id3=" . $_REQUEST["hidId1"];
            //$Combo=$_REQUEST["hidId3"];
            //$Combo2=$_REQUEST["hidId2"];

            if ($_REQUEST["dsniv3"]==$_REQUEST["newds3"]) {
                header("location: trn_SubCategorias.php?SoloError=0&CmbEmpresa=$Combo&CmbCategoria=$Combo2&opc=2");
            }
            break;
        case "E":
            $strSql="delete from solotb_nivel3";
//            $strSql .= " where id2=" . $_REQUEST["hidId2"];
//            $strSql .= "   and id3=" . $_REQUEST["hidId1"];
            $strSql .= " where id3 = {$_REQUEST["hidId1"]}";
//            $Combo=$_REQUEST["hidId3"];
//            $Combo2=$_REQUEST["hidId2"];
            break;
        default:
//Ingresa cuando recien Graba un registro
            $strSql="insert into solotb_nivel3 values (";
            //$strSql .= $_REQUEST["CmbCategoria"] . ",";
            $strSql .= $_REQUEST["hidId1"] . ",'";
            $strSql .= ($_REQUEST["ATxtDesc"]) . "')";
            //$Combo=$_REQUEST["CmbEmpresa"];
            //$Combo2=$_REQUEST["CmbCategoria"];
            break;
    }
    //echo $strSql;
    $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
            $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
    if(!$oConexion->EjecutarQuery($strSql)) {

        $strMsg="trn_SubCategorias.php?SoloError=1&opc=2&des={$oConexion->getErrorMessage()}";
    }else {
        $strMsg="trn_SubCategorias.php?SoloError=0&opc=2";
    }

    $oConexion->Cerrar();

    header("location:$strMsg");
}

//----
//Ingresa aqui cuando da submit en la forma para modificar o eliminar definitivo
//----

//Ingresa aqui cuando la primera vez ingresa
switch ($_REQUEST["opc"]) {
    case "M":
        $boton ="<input type='submit' name='CmdGrabar' value='Modificar' class='SoloStyle_Boton'>";
        $oculto="<input type='hidden' name='opc' value='M'>";
        $titulo="Modificaci&oacute;n de Categor&iacute;a";
        break;
    case "E":
        $boton ="<input type='submit' name='CmdGrabar' value='Eliminar' class='SoloStyle_Boton'>";
        $oculto="<input type='hidden' name='opc' value='E'>";
        $titulo="Eliminaci&oacute;n de Categor&iacute;a";
        break;
}

//if ($_Request["CmbEmpresa"]=="") {
//    $strSql="select * from solotb_nivel1 where id1=" . $_REQUEST["id1"];
//}else {
//    $strSql="select * from solotb_nivel1 where id1=" . $_REQUEST["CmbEmpresa"];
//}

//echo $_REQUEST["id1"];
//echo $strSql;

//$oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
//        $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
//if(!$oConexion->EjecutarQuery($strSql)) {
//    $strERROR=1;
//    $err=0;
//}
//$arrModu = $oConexion->getData("NUM");
//
//$Desc = $arrModu[0][1];
//$oConexion->Cerrar();


//if ($_REQUEST["CmbCategoria"]=="" ) {
//    $strSql="select * from solotb_nivel2 where id2=" . $_REQUEST["id2"];
//}else
//    $strSql="select * from solotb_nivel2 where id2=" . $_REQUEST["CmbCategoria"];

//$oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
//        $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
//if(!$oConexion->EjecutarQuery($strSql)) {
//
//    $strERROR=1;
//    $err=0;
//}

//$arrModu=$oConexion->getData("NUM");
//$Desc1=$arrModu[0][2];
////'response.write desc1
//$oConexion->Cerrar();

?>

<html>
    <head>
        <title>Documentacion</title>
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css"></head>

    <body topmargin=0 leftmargin=0>
        <p align="center" class="SoloStyle_TituloPaginas"><?php echo $titulo;?></p>

        <form name="frmIngreso" action="trn_GrabaSubCategoria.php" method="POST">
            <table border="0" width="70%" align="center">
                <tr>
                    <td class="SoloStyle_Etiqueta">Categor&iacute;a</td>
                    <td class="SoloStyle_Texto">
                        <input type="text"   maxlenght="50" size="50" name="newds3" class="SoloStyle_Texto" value="<?php echo $_REQUEST["ds3"];?>">
                        <input type="hidden" maxlenght="50" size="50" name="dsniv3" class="SoloStyle_Texto" value="<?php echo $_REQUEST["ds3"];?>">
                        <input type="hidden" maxlenght="50" size="50" name="hidId1" class="SoloStyle_Texto" value="<?php echo $_REQUEST["id3"];?>"></td>
                </tr>
            </table>

            <br><center><?php echo $boton;
echo $oculto?></center>
        </form>

    </body>
</html>
